remove a specific element from an array php

101

if (($key = array_search('strawberry', $array)) !== false) {
    unset($array[$key]);
}
$array=array_diff($array,['strawberry']);


if (($key = array_search('strawberry', $array)) !== false) {
    unset($array[$key]);
}

Comments

Submit
0 Comments